package com.sentiment.tools;

import java.util.ArrayList;
import java.util.List;

import org.bson.Document;

public class Paging {
	
	/**
	 * 查询后分页方法
	 * @param alltlist 分页前数据
	 * @param page 页码
	 * @param count 每页数据条数
	 * @return 分页后数据
	 */
	public static List<Document> paging(List<Document> alltlist, int page, int count){
		
		if(alltlist.size() <= count){
			return alltlist;
		}
		
		List<Document> pagetlist = new ArrayList<>();
		
		int start = (page - 1) * count;
		int end = start + count;
		int i = 0;
		int size = alltlist.size();
		while(i < size){
			
			if(i >= start && i < end){
				pagetlist.add(alltlist.get(i));
			}
			i++;
		}
		
		return pagetlist;
		
	}
	
	public static List<String> pagingStr(List<String> alltlist, int page, int count){
		
		if(alltlist.size() <= count){
			return alltlist;
		}
		
		List<String> pagetlist = new ArrayList<>();
		
		int start = (page - 1) * count;
		int end = start + count;
		int i = 0;
		int size = alltlist.size();
		while(i < size){
			
			if(i >= start && i < end){
				pagetlist.add(alltlist.get(i));
			}
			i++;
		}
		
		return pagetlist;
		
	}
	
}
